<?php

namespace apiend\controllers;

use Yii;
use apiend\components\Controller;
use common\base\ModelHttpException;
use common\logics\RouterLogic;
use common\models\app\AppVersion;
use common\models\app\AppBootSplash;
use apiend\models\DeviceForm;

/**
 * 全局应用接口
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class GlobalController extends Controller {

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     * @return array the allowed HTTP verbs.
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
            'register' => ['POST'],
        ];
    }

    /**
     * 获取应用版本升级
     * @return mixed
     */
    public function actionVersion() {
        return AppVersion::getLatest();
    }

    /**
     * 注册设备信息（推送消息时使用）
     * @return mixed
     */
    public function actionRegister() {
        $model = new DeviceForm();
        if (!$model->load(Yii::$app->request->post(), '')) {
            throw new ModelHttpException('提交时数据未加载成功');
        }
        $model->device = $this->token->device;
        return $model->register();
    }

}
